// const BASEURL = 'http://192.168.5.37:8847'; // 公司
// const BASEURL = 'http://192.168.43.136:8847';
// const BASEURL = 'http://192.168.0.104:8847';  //公寓
const BASEURL = 'http://8.140.154.128:8847';  //线上
const json2url = (datas) => {
	if (!datas) {
		return ''
	}
	let arr = [];
	for (let key in datas) {
		arr.push(key + "=" + datas[key]);
	}
	return '?' + arr.join("&");
}
const addDataOut = (datas,pageNo,pageSize) => {
	return {"data":datas,"pageNo":pageNo,"pageSize":pageSize};
}
const addAuthorization = (header) => {
	const token = uni.getStorageSync("token");
	if (token != null && token.length > 0) {
		header.authorization = token;
	}
	return header;
}
const http = ({
	url,
	method = 'post',
	data = {},
	pageNo = 1,
	pageSize = 10,
	params = {},
	header = {
		'content-type': 'application/json',
		"Access-Control-Allow-Origin": "*",
	}
}) => {
	if (!url) {
		return
	}
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASEURL + url + json2url(params),
			method,
			data: addDataOut(data,pageNo,pageSize),
			header: addAuthorization(header),
			success(res) {
				resolve(res);
			},
			fail(err) {
				reject(err)
			}
		})
	})
}
export default http
